from django.db import models

# Create your models here.


class Areas(models.Model):
    name = models.CharField(max_length=20, verbose_name='地区')
    # related_name='subs',例 一查多 area.areas_set.all()可以写成area.subs.all()
    # blank=True admin后台管理可以不定义父类,正常是需要定义
    parent = models.ForeignKey('self', on_delete=models.SET_NULL, related_name='subs',
                               null=True, blank=True, verbose_name='上级行政区划')
    class Meta:
        db_table = 'tb_areas'
        verbose_name = '行政区划'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
